﻿using System.Text;
using System.Threading.Tasks;
using GeneralUpdate.Common.Compress;
using GeneralUpdate.Common.Internal.Pipeline;

namespace GeneralUpdate.ClientCore.Pipeline;

public class CompressMiddleware : IMiddleware
{
    public Task InvokeAsync(PipelineContext? context)
    {
        return Task.Run(() =>
        {
            var format = context.Get<string>("Format");
            var sourcePath = context.Get<string>("ZipFilePath");
            var patchPath = context.Get<string>("PatchPath");
            var encoding = context.Get<Encoding>("Encoding");
            var appPath = context.Get<string>("SourcePath");
            var patchEnabled = context.Get<bool?>("PatchEnabled");
            
            CompressProvider.Decompress(format, sourcePath,patchEnabled == false ? appPath : patchPath, encoding);
        });
    }
}